﻿namespace WMS6.Web.Billing
{
    using System;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using WMS6.Web;
    using WMS6.Web.BillingServiceRef;

    public class AccessorialChargesDetail : BasePage
    {
        protected Button btnCancel;
        protected Button btnSave;
        protected HtmlForm F9183;
        protected HtmlInputHidden hdnFlag;
        protected HtmlInputHidden hdnFrom;
        protected HtmlInputHidden hdnTariffID;
        protected HtmlInputHidden hdnType;
        protected HtmlHead Head1;
        protected HtmlImage img1;
        protected HtmlImage img3;
        protected Label lblAccessorialChargesID;
        protected Label lblAccessorialID;
        protected Label lblAreaDetail;
        protected Label lblBilledUnits;
        protected Label lblChargeInvocation;
        protected Label lblChargePerUnit;
        protected Label lblChargeUnit;
        protected Label lblDebit;
        protected Label lblDescr;
        protected Label lblGeneralLedgerID;
        protected Label lblLineID;
        protected Label lblLot;
        protected Label lblMsg;
        protected Label lblOrderID;
        protected Label lblOwnerID;
        protected Label lblQty;
        protected Label lblRateID;
        protected Label lblSkuID;
        protected Label lblTaxGroupID;
        protected HtmlLink mycss;
        protected Label one1;
        protected ScriptManager ScriptManager1;
        protected TextBox txtAccessorialChargesID;
        protected TextBox txtAccessorialID;
        protected TextBox txtBilledUnits;
        protected TextBox txtChargeInvocation;
        protected TextBox txtChargePerUnit;
        protected TextBox txtChargeUnit;
        protected TextBox txtDebit;
        protected TextBox txtDescr;
        protected TextBox txtGeneralLedgerID;
        protected TextBox txtLineID;
        protected TextBox txtLot;
        protected TextBox txtOrderID;
        protected TextBox txtOwnerID;
        protected TextBox txtQty;
        protected TextBox txtRateID;
        protected TextBox txtSkuID;
        protected TextBox txtTaxGroupID;

        protected void btnCancel_Click(object sender, EventArgs e)
        {
            base.Server.Transfer(string.Format("AccessorialCharges.aspx?from={0}&detail={1}&ID={2}&Type={3}", new object[] { base.UrlEncode(this.hdnFrom.Value), "1", base.UrlEncode(this.txtOrderID.Text), base.UrlEncode(this.hdnType.Value) }));
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(this.txtAccessorialID.Text.Trim()))
            {
                this.lblMsg.Text = base.GetGlobalMsgResource("F9180_005");
            }
            else if (string.IsNullOrEmpty(this.txtRateID.Text))
            {
                this.lblMsg.Text = base.GetGlobalMsgResource("F9180_006");
            }
            else if (string.IsNullOrEmpty(this.txtGeneralLedgerID.Text))
            {
                this.lblMsg.Text = base.GetGlobalMsgResource("F9180_007");
            }
            else
            {
                try
                {
                    AccessorialChargesInfo AccessorialChargesInfo = new AccessorialChargesInfo {
                        AccessorialChargesID = this.txtAccessorialChargesID.Text,
                        AccessorialID = this.txtAccessorialID.Text,
                        AccessorialType = this.hdnType.Value,
                        OwnerID = this.txtOwnerID.Text
                    };
                    if (!string.IsNullOrEmpty(this.txtBilledUnits.Text))
                    {
                        AccessorialChargesInfo.BilledUnits = decimal.Parse(this.txtBilledUnits.Text);
                    }
                    else
                    {
                        AccessorialChargesInfo.BilledUnits = 0M;
                    }
                    AccessorialChargesInfo.ChargeInvocation = this.txtChargeInvocation.Text;
                    if (!string.IsNullOrEmpty(this.txtChargePerUnit.Text))
                    {
                        AccessorialChargesInfo.ChargePerUnit = decimal.Parse(this.txtChargePerUnit.Text);
                    }
                    else
                    {
                        AccessorialChargesInfo.ChargePerUnit = 0M;
                    }
                    AccessorialChargesInfo.ChargeUnit = this.txtChargeUnit.Text;
                    if (!string.IsNullOrEmpty(this.txtDebit.Text))
                    {
                        AccessorialChargesInfo.Debit = decimal.Parse(this.txtDebit.Text);
                    }
                    else
                    {
                        AccessorialChargesInfo.Debit = 0M;
                    }
                    AccessorialChargesInfo.Descr = this.txtDescr.Text;
                    AccessorialChargesInfo.GeneralLedgerID = this.txtGeneralLedgerID.Text;
                    AccessorialChargesInfo.Lot = this.txtLot.Text;
                    AccessorialChargesInfo.OrderID = this.txtOrderID.Text;
                    AccessorialChargesInfo.OrderLineID = int.Parse(this.txtLineID.Text);
                    AccessorialChargesInfo.RateID = this.txtRateID.Text;
                    AccessorialChargesInfo.TaxGroupID = this.txtTaxGroupID.Text;
                    AccessorialChargesInfo.SkuID = this.txtSkuID.Text;
                    AccessorialChargesInfo.Qty = decimal.Parse(this.txtQty.Text);
                    AccessorialChargesInfo.IsChecked = "N";
                    AccessorialChargesInfo.CreatedBy = base.UserInfo.UserID;
                    this.lblMsg.Text = BillingServiceClientProxy.GetInstance().InsertAccessorialCharges(AccessorialChargesInfo) + base.GetGlobalMsgResource("F9180_008");
                    this.hdnFlag.Value = "1";
                    base.Server.Transfer(string.Format("AccessorialCharges.aspx?from={0}&detail={1}&ID={2}&Type={3}", new object[] { base.UrlEncode(this.hdnFrom.Value), "1", base.UrlEncode(this.txtOrderID.Text), base.UrlEncode(this.hdnType.Value) }));
                }
                catch (Exception ex)
                {
                    this.lblMsg.Text = base.GetGlobalMsgResource("F9180_009") + ex.Message;
                }
            }
        }

        private void LoadData()
        {
            if (!string.IsNullOrEmpty(base.Request.QueryString["from"]))
            {
                string from = base.Request.QueryString["from"];
                this.hdnFrom.Value = from;
            }
            this.txtOrderID.Text = base.Request.QueryString["OrderID"];
            this.txtLineID.Text = base.Request.QueryString["LineID"];
            this.txtSkuID.Text = base.Request.QueryString["SkuID"];
            this.txtLot.Text = base.Request.QueryString["Lot"];
            this.txtOwnerID.Text = base.Request.QueryString["OwnerID"];
            this.hdnType.Value = base.Request.QueryString["Type"];
            this.txtQty.Text = base.GetPreferenceDigit(base.Request.QueryString["Qty"]);
            if (!string.IsNullOrEmpty(base.Request.QueryString["Key"]))
            {
                this.txtLineID.Text = "0";
                this.txtLot.Text = base.GetGlobalMsgResource("F9180_004");
                this.txtQty.Text = "0";
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!base.IsPostBack)
            {
                base.InitPage(this.Page);
                this.LoadData();
            }
        }
    }
}

